//
//  NodePool.hpp
//  client
//
//  Created by will on 24/01/2018.
//

#ifndef NodePool_hpp
#define NodePool_hpp

#include <unordered_map>
#include <queue>
#include <string>

namespace cocos2d
{
    class Node;
}

class NodePool
{
public:
    static NodePool* getInstance();
    static void destroyInstance();
public:
    ~NodePool();
public:
    void put(cocos2d::Node* node);
    void put(cocos2d::Node* node, const std::string& key);
    cocos2d::Node* getByKey(const std::string& key);
    
    template<typename T>
    bool get(T& t);
    
    size_t size(const std::string& key) const;
    void clear();
private:
    typedef std::queue<cocos2d::Node*> NodeList;
    std::unordered_map<std::string, NodeList> _pool;
};

#endif /* NodePool_hpp */
